package com.lxj.fast_android_demo.util;

/**
 * 数据集数据处理工具类
 * 
 * @author LiangXiangJu
 * @creationTime 2014-7-2 下午1:30:22
 * @version
 */
public class DatasetUtil {

	/**
	 * 字符串判空
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-2 下午1:27:12
	 * @version
	 * @param str
	 * @return
	 */
	public static boolean isStrEmpty(String str) {
		return null == str || "".equals(str.trim());
	}

	/**
	 * 字符串强制转为整数(字符串为空或不是数字时返回0，是数字但不是整数的取整返回)
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-2 下午1:27:30
	 * @version
	 * @param strInt
	 * @return
	 */
	public static int forceParseInt(String strInt) {
		if (isStrEmpty(strInt)) {
			return 0;
		}
		try {
			return Integer.parseInt(strInt.trim());
		} catch (NumberFormatException e) {
			try {
				return (int) Double.parseDouble(strInt.trim());
			} catch (NumberFormatException e1) {
				return 0;
			}
		}
	}

	/**
	 * 字符串转为整数(字符串为空或不是数字时返回0)
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-2 下午1:27:57
	 * @version
	 * @param strInt
	 * @return
	 */
	public static int parseInt(String strInt) {
		if (isStrEmpty(strInt)) {
			return 0;
		}
		try {
			return Integer.parseInt(strInt.trim());
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	/**
	 * 字符串转为double(字符串为空或不是数字时返回0)
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-2 下午1:29:35
	 * @version
	 * @param strDouble
	 * @return
	 */
	public static double parseDouble(String strDouble) {
		if (isStrEmpty(strDouble)) {
			return 0;
		}
		try {
			return Double.parseDouble(strDouble.trim());
		} catch (NumberFormatException e1) {
			return 0;
		}
	}

	/**
	 * 判断字符串是否为数字
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-4 上午10:47:35
	 * @version
	 * @param strInt
	 * @return
	 */
	public static boolean isNumberData(String strInt) {
		if (isStrEmpty(strInt)) {
			return false;
		}
		try {
			Integer.parseInt(strInt.trim());
			return true;
		} catch (NumberFormatException e) {
			try {
				Double.parseDouble(strInt.trim());
				return true;
			} catch (NumberFormatException e1) {
				return false;
			}
		}
	}

}
